import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { ToolTipItem } from "../../../../com/mui/manager/ToolTipItem";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { Global } from "../../../../com/gengine/global/Global";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { TweenMax } from "../../../../com/greensock/TweenMax";
import { DataEvent } from "../../events/DataEvent";
import { GameManager } from "../../manager/GameManager";
import { WalkthroughWindow } from "./WalkthroughWindow";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class WalkthroughIcon
    
    export  class WalkthroughIcon extends View
    {
        constructor()
        {
            super();
            if (WalkthroughIcon._instance != null) 
            {
                throw new Error(" WalkthroughIcon 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.layer = LayerManager.uiLayer;
            this._clickArea = new ToolTipItem();
            this._clickArea.buttonMode = true;
            this._icon = ObjCreate.createBg(0, 0, -1, -1, this._clickArea, ImagesConst.Walkthrough);
            this._clickArea.graphics.beginFill(16777215, 0);
            this._clickArea.graphics.drawRect(0, 0, 61, 62);
            this._clickArea.graphics.endFill();
            this._clickArea.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            this._clickArea.x = 20;
            this._clickArea.cacheAsBitmap = true;
            this.addChild(this._clickArea);
            this._clickArea.toolTipData = HTMLUtil.addColor(Language.getString(51040), "#ffffff");
            this._flashSecTimer = new Object /* flash.utils.Timer */(500);
            this._flashSecTimer.repeatCount = 20;
            this._flashSecTimer.addEventListener(flash.events.TimerEvent.TIMER, this.onFlashTimeHandler);
            this._flashSecTimer.addEventListener(flash.events.TimerEvent.TIMER_COMPLETE, this.onFlashTimeCompleteHandler);
            this._flashSecTimer.start();
            this._showBtn = ObjCreate.createGButton("", 90, 8, 17, 17, this, "PetMenuUpBtn");
            this._showBtn.rotation = 90;
            this._showBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onShowBtnClickHandler);
            this._showBtn.toolTipData = HTMLUtil.addColor(Language.getString(51114), "#ffffff");
            x = (Global.stage.stageWidth - 80) / 2;
            y = (Global.stage.stageHeight - 80) / 2;
            Dispatcher.addEventListener(EventName.StageResize, this.onStageResizeHandler);
            return;
        }

        public flashIcon(arg1: Boolean=true): void
        {
            if (arg1) 
            {
                this._flashSecTimer.reset();
                this._flashSecTimer.start();
            }
            else 
            {
                this._flashSecTimer.stop();
            }
            return;
        }

        /* internal  */tween(): void
        {
            var loc1=Global.stage.stageWidth - 90;
            var loc2=450 + 20 * Global.stage.stageHeight / 1000;
            TweenMax.to(this, 2, {"x": loc1, "y": loc2});
            return;
        }

        /* internal  */stageResize(): void
        {
            x = Global.stage.stageWidth - 90;
            y = 450 + 20 * Global.stage.stageHeight / 1000;
            return;
        }

        /* internal  */onFlashTimeHandler(arg1: Object /* flash.events.TimerEvent */): void
        {
            this._icon.visible = !this._icon.visible;
            return;
        }

        /* internal  */onStageResizeHandler(arg1: DataEvent): void
        {
            this.stageResize();
            return;
        }

        /* internal  */onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            GameManager.instance.popupView(WalkthroughWindow.instance);
            this.flashIcon(false);
            this._icon.visible = true;
            return;
        }

        /* internal  */onFlashTimeCompleteHandler(arg1: Object /* flash.events.TimerEvent */): void
        {
            this._icon.visible = true;
            return;
        }

        /* internal  */onShowBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._isHided) 
            {
                this._isHided = false;
                this._showBtn.rotation = 90;
                this._showBtn.x = 90;
                this._showBtn.y = 8;
                TweenMax.to(this._clickArea, 0.5, {"x": 20});
                this._showBtn.toolTipData = HTMLUtil.addColor(Language.getString(51114), "#ffffff");
            }
            else 
            {
                this._isHided = true;
                this._showBtn.rotation = -90;
                this._showBtn.x = 73;
                this._showBtn.y = 25;
                TweenMax.to(this._clickArea, 0.5, {"x": 100});
                this._showBtn.toolTipData = HTMLUtil.addColor(Language.getString(51115), "#ffffff");
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.tween();
            return;
        }

        public static get instance(): WalkthroughIcon
        {
            if (WalkthroughIcon._instance == null) 
            {
                WalkthroughIcon._instance = new WalkthroughIcon();
            }
            return WalkthroughIcon._instance;
        }

        /* internal */ /* var */_clickArea: ToolTipItem;

        /* internal */ /* var */_icon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_showBtn: GButton;

        /* internal */ /* var */_flashSecTimer: Object /* flash.utils.Timer */;

        /* internal */ /* var */_isHided: Boolean;

        /* internal */ static /* var */_instance: WalkthroughIcon;
    }
